package com.ag.zhh.vo;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import com.ag.bean.TbDeptType;

@Entity
@Table(name = "TB_USER_DEPT", schema = "dbo")
public class UserDept {
	private String udId;
	private UserDeptContact userDeptContact;//负责人
	private UserDept userDept;					//上级部门
	private TbDeptType tbDeptType;
	private String udName;
	private Long udIf; //1 为应急部门，其它为日常部门
	private String udFax;
	private String udTel;
	private String udPhone;
	private String GId;
	private String GDesc;
	private String GCode;
	private String GAdmin;
	private Set<UserDept> userDepts = new HashSet<UserDept>(0);			//子部门
	private List<UserDept> childdepts = new LinkedList<UserDept>();			//子部门
	private Set<UserDeptContact> userDeptContacts = new HashSet<UserDeptContact>(0);		//部门联系人
	private String a;
	
	@Id
	@Column(name = "UD_ID", unique = true, nullable = false, length = 12)
	public String getUdId() {
		return this.udId;
	}

	public void setUdId(String udId) {
		this.udId = udId;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "UD_UID")
	public UserDeptContact getTbUser() {
		return this.userDeptContact;
	}

	public void setTbUser(UserDeptContact tbUser) {
		this.userDeptContact = tbUser;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "UD_FID")
	public UserDept getTbUserDept() {
		return this.userDept;
	}

	public void setTbUserDept(UserDept tbUserDept) {
		this.userDept = tbUserDept;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "UD_TYPE")
	public TbDeptType getTbDeptType() {
		return this.tbDeptType;
	}

	public void setTbDeptType(TbDeptType tbDeptType) {
		this.tbDeptType = tbDeptType;
	}

	@Column(name = "UD_NAME", length = 50)
	public String getUdName() {
		return this.udName;
	}

	public void setUdName(String udName) {
		this.udName = udName;
	}

	@Column(name = "UD_IF", precision = 22, scale = 0)
	public Long getUdIf() {
		return this.udIf;
	}

	public void setUdIf(Long udIf) {
		this.udIf = udIf;
	}

	@Column(name = "UD_FAX", length = 20)
	public String getUdFax() {
		return this.udFax;
	}

	public void setUdFax(String udFax) {
		this.udFax = udFax;
	}

	@Column(name = "UD_TEL", length = 20)
	public String getUdTel() {
		return this.udTel;
	}

	public void setUdTel(String udTel) {
		this.udTel = udTel;
	}

	@Column(name = "UD_PHONE", length = 12)
	public String getUdPhone() {
		return this.udPhone;
	}

	public void setUdPhone(String udPhone) {
		this.udPhone = udPhone;
	}
	
	@Column(name = "G_ID", length = 50)
	public String getGId() {
		return this.GId;
	}

	public void setGId(String GId) {
		this.GId = GId;
	}

	@Column(name = "G_DESC", length = 500)
	public String getGDesc() {
		return this.GDesc;
	}

	public void setGDesc(String GDesc) {
		this.GDesc = GDesc;
	}

	@Column(name = "G_CODE", length = 50)
	public String getGCode() {
		return this.GCode;
	}

	public void setGCode(String GCode) {
		this.GCode = GCode;
	}

	@Column(name = "G_ADMIN", length = 300)
	public String getGAdmin() {
		return this.GAdmin;
	}

	public void setGAdmin(String GAdmin) {
		this.GAdmin = GAdmin;
	}



	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "tbUserDept")
	@javax.persistence.OrderBy("GCode")
	public Set<UserDept> getTbUserDepts() {
		return this.userDepts;
	}

	public void setTbUserDepts(Set<UserDept> tbUserDepts) {
		this.userDepts = tbUserDepts;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER, mappedBy = "tbUserDept")
	@javax.persistence.OrderBy("GCode")
	public List<UserDept> getChilddepts() {
		return childdepts;
	}

	public void setChilddepts(List<UserDept> childdepts) {
		this.childdepts = childdepts;
	}

	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@JoinTable(name = "TB_USERDEPT_USER", schema = "dbo", joinColumns = { @JoinColumn(name = "UD_ID", nullable = false, updatable = false) }, inverseJoinColumns = { @JoinColumn(name = "U_ID", nullable = false, updatable = false) })
	@javax.persistence.OrderBy("oacode")
	public Set<UserDeptContact> getTbUsers() {
		return this.userDeptContacts;
	}

	public void setTbUsers(Set<UserDeptContact> tbUsers) {
		this.userDeptContacts = tbUsers;
	}
	
	@Column(name = "A")
	public String getA() {
		return a;
	}

	public void setA(String a) {
		this.a = a;
	}
	
}
